package leetcode

// 横向对比
func longestCommonPrefix(strs []string) string {
	if len(strs) == 0 {
		return ""
	}
	for i := len(strs[0]); i > 0; i-- {
		strInit := strs[0][:i]
		//fmt.Println(strInit)
		for k, v := range strs {
			if len(v) < i {
				break
			}
			if strInit != v[:i] {
				break
			} else {
				if strInit == v[:i] && k == len(strs)-1 {
					return strInit
				}
			}
		}
	}

	return ""
}
